package com.cms.common.action;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("common")
public class CommonController {
//	@Resource
//	private MailSender mailSender;
	/*@RequestMapping(value = "/o_upload_image")
	public void uploadAjax(@RequestParam(value = "uploadFile") MultipartFile file,
						   HttpServletRequest request, HttpServletResponse response) {
		File uploadDirPath = new File(request.getSession().getServletContext()
				.getRealPath("/upload")+"/"+ FileNameUtils.genPathName()+"/");

		MultipartFile image = file;
		String fileType=image.getOriginalFilename().substring(image.getOriginalFilename().lastIndexOf(".")+1);
		File destFile = new File(uploadDirPath.getAbsoluteFile() + "/"
				+ FileNameUtils.genFileName(fileType));
		try {
			if (!uploadDirPath.exists()) {
				uploadDirPath.mkdirs();
				uploadDirPath.setExecutable(true);
			}
			FileCopyUtils.copy(image.getBytes(), destFile);
			
			
			String destPath = "/upload/"+FileNameUtils.genPathName()+"/"
					+ destFile.getName();
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("path", destPath);
			response.setContentType("text/html;charset=utf-8");
			response.getWriter().println(jsonObject.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping(value = "/v_image_area_select")
	public String imageAreaSelect(){
		return "common/img_cute";	
	}
	
	@RequestMapping(value = "/cuteImage")
	public String cuteImag(HttpServletRequest request, @RequestParam String imgSrcPath, @RequestParam Integer imgWidth, @RequestParam Integer imgHeight, @RequestParam Integer imgLeft, @RequestParam Integer imgTop){
		try {
			String imagePath = request.getSession().getServletContext().getRealPath(imgSrcPath);
			ImageHelper.cutImage(imagePath,imagePath,imgLeft,imgTop,imgWidth,imgHeight);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
		return "common/img_cute";	
	}*/
	
//	@RequestMapping(value = "/sendEmail")
//	@ResponseBody
//	public String sendEmail(){
//		SimpleMailMessage mail = new SimpleMailMessage(); //<span style="color: rgb(255, 0, 0);">注意SimpleMailMessage只能用来发送text格式的邮件</span>
//		try {
//			mail.setTo("45115517@qq.com");//接受者
//			mail.setFrom("1624413124@qq.com");//发送者,这里还可以另起Email别名，不用和xml里的username一致
//			mail.setSubject("spring mail test!");//主题
//			mail.setText("springMail的简单发送测试");//邮件内容
//			mailSender.send(mail);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return "ok";
//	}

	@RequestMapping("/testExceptionMapping")
	public String testExceptionMapping(){
		int arrays[] = new int[10];
		System.out.println(arrays[11]);
		return "hello";
	}
}
